package com.ciaojian.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ciaojian.core.model.Store;
import com.ciaojian.core.model.dto.StoreDTO;
import com.ciaojian.core.model.vo.FranchiseesStoreVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Atlakyn
 */
@Mapper
public interface StoreMapper extends BaseMapper<Store> {
    /**
     * 查询发型师所属门店
     *
     * @param workerId 发型师ID
     * @return 所属门店
     */
    Store getByWorkerId(Integer workerId);

    /**
     * 获取用户邀请发型师所属门店
     *
     * @param userId 用户ID
     * @return 用户邀请发型师所属门店
     */
    Store getUserInviterStore(Integer userId);

    /**
     * 根据发型师ID查询门店
     *
     * @param workerId 发型师ID
     * @return 门店
     */
    @Select("SELECT store_id AS id, store_name AS title FROM d_worker WHERE id = #{workerId} ")
    StoreDTO findByWorkerId(@Param("workerId") Integer workerId);

    /**
     * 根据 id 查找 StoreDTO
     *
     * @param id 门店id
     * @return 门店数据
     */
    @Select("SELECT * FROM d_store WHERE id = #{id} ")
    StoreDTO selectStoreDTO(@Param("id") Integer id);

    /**
     * 根据 id 查询店名
     *
     * @param id id
     * @return 店名
     */
    @Select("SELECT title FROM d_store WHERE id = #{id}")
    String getTitleById(@Param("id") Integer id);

    /**
     * 根据店名查询 UUID
     *
     * @param storeName 店名
     * @return 店铺 UUID
     */
    @Select("SELECT open_shop_uuid FROM d_store WHERE title = #{storeName} AND is_del = 0")
    String getOpenShopUuidByStoreName(String storeName);

    @Select("SELECT discount FROM d_member LIMIT 0,1")
    String getDiscount();

    @Select("SELECT COUNT(1) FROM d_order dor " +
            "LEFT JOIN d_worker dw ON dw.id = dor.worker_id " +
            "WHERE dor.worker_id = #{id} " +
            "AND dor.`status` IN (0,1) " +
            "AND TO_DAYS(dor.add_time) = TO_DAYS(NOW()) " +
            "AND dw.worker_status = 0")
    Integer getddCount(String id);

    @Select("SELECT COUNT(dor.id) FROM d_order dor\n" +
            "            LEFT JOIN d_worker dw ON dor.worker_id = dw.id and dw.worker_status = 0 \n" +
            "            WHERE dor.store_id = #{id}\n" +
            "            AND dor.`status` in (0,1)")
    Integer getStoreNum(@Param("id") String id);

    FranchiseesStoreVo getFranchiseesStoreInfo(@Param("storeId") Integer storeId);
}
